package com.example.experiment3.controlller;

import com.example.experiment3.entity.RegionEntity;
import com.example.experiment3.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@Controller
public class RegionStatus {

    @Autowired
    RegionService regionService;

    @RequestMapping("/region")
    String RegionShow(Model model) throws IOException {
        List<RegionEntity> regionEntitys=regionService.getAllData();
        model.addAttribute("regionEntitys",regionEntitys);
        return "show";
    }
    @RequestMapping("/region/search")
    public String RegionShowCP(@RequestParam(required =false) String country, @RequestParam(required =false,name="province") String province, Model model) throws IOException {
        //System.out.println(country);
        List<RegionEntity> regionEntitys=regionService.getCountryProvinceData(country,province);
        System.out.println(regionEntitys);
        if(model!=null)
             model.addAttribute("regionEntitys",regionEntitys);
        return "show";
    }
}
